home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / clients / editres / setvalue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  3.8 KB  |  124 lines

  1. /*
  2.  * $XConsortium: setvalues.c,v 1.4 91/03/20 17:08:49 gildea Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Chris D. Peterson, MIT X Consortium
  24.  */
  25.  
  26. #ifdef MSDOS
  27. #include "X11/Intrinsc.h"      /* QDK 05/11/1994 12:54pm. */
  28. #else
  29. #include "X11/Intrinsic.h"
  30. #endif
  31. #include <X11/StringDefs.h>
  32. #include <X11/Xresource.h>
  33.  
  34. #include <stdio.h>
  35.  
  36. #include <X11/Xaw/AsciiText.h>
  37. #include <X11/Xaw/Cardinals.h>    
  38. #include <X11/Xfuncs.h>
  39. #include <X11/Xos.h>
  40. #include "editresP.h"
  41.  
  42. extern WNode * FindNode();
  43. extern void AddString();
  44.  
  45. #define RESOURCE_NAME ("name")
  46. #define RESOURCE_CLASS ("Class")
  47.  
  48. /*    Function Name: PrintSetValuesError
  49.  *    Description: Allow the SetValues error to be printed.
  50.  *    Arguments: event - the set values call that caused this event.
  51.  *    Returns: str - a string contining the errors.
  52.  */
  53.  
  54. char *
  55. PrintSetValuesError(event)
  56. Event * event;
  57. {
  58.     char * errors = NULL;
  59.     WNode * node;
  60.     int i;
  61.     SetValuesEvent * sv_event = (SetValuesEvent *) event;
  62.     char buf[BUFSIZ];
  63.  
  64.     if (sv_event->num_entries == 0) 
  65.     return(XtNewString("SetValues was Successful."));
  66.  
  67.     for (i = 0 ; i < (int)sv_event->num_entries ; i++) {
  68.     node = FindNode(global_tree_info->top_node,
  69.             sv_event->info[i].widgets.ids, 
  70.             sv_event->info[i].widgets.num_widgets);
  71.  
  72.     if (node == NULL) {
  73.         sprintf(buf, "Editres Internal Error: Unable to FindNode.\n");
  74.         AddString(&errors, buf); 
  75.         continue;
  76.     }
  77.  
  78.     sprintf(buf, "%s(0x%lx) - %s\n", node->name, node->id,
  79.         sv_event->info[i].message);
  80.     AddString(&errors, buf);
  81.     }
  82.     return(errors);
  83. }
  84.  
  85. /*    Function Name: GetResourceValueForSetValues(node);
  86.  *    Description: Returns the value that should be sent to SetValues.
  87.  *    Arguments: node - the node which contains the resource box.
  88.  *    Returns: value - allocated value.
  89.  */
  90.  
  91. char *
  92. GetResourceValueForSetValues(node, size)
  93. WNode * node;
  94. unsigned short * size;
  95. {
  96.     Arg args[1];
  97.     char *ptr, *temp;
  98.     XrmDatabase db = NULL;
  99.     XrmValue value;
  100.  
  101.     XtSetArg(args[0], XtNstring, &ptr);
  102.     XtGetValues(node->resources->res_box->value_wid, args, ONE);
  103.  
  104.     /*
  105.      * This makes sure that exactly the same thing happens during a set
  106.      * values, that would happend of we were to insert this value into
  107.      * the resource database.
  108.      */
  109.  
  110.     temp = XtMalloc(sizeof(char) * (strlen(ptr) + strlen(RESOURCE_NAME) + 2));
  111.     sprintf(temp, "%s:%s", RESOURCE_NAME, ptr);
  112.     XrmPutLineResource(&db, temp);
  113.     XtFree(temp);
  114.  
  115.     XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value);
  116.  
  117.     ptr = XtMalloc(sizeof(char) * value.size);
  118.     bcopy(value.addr, ptr, value.size);
  119.     XrmDestroyDatabase(db);
  120.     
  121.     *size = (unsigned short) value.size;
  122.     return(ptr);
  123. }
  124.